package com.luckeys.vo;

import java.io.Serializable;
import java.util.List;

public class PageVO<T> implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4423793938167790083L;
	private int curPage = 1;
	private int pageSize = 15;
	private Integer totalRecords;
	private Integer totalPages=0;
	private int startIndex;
	private int endIndex;
	private List<T> data;

	public PageVO() {

	}
	
	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	public PageVO(int pageSize, int curPage) {
		this.curPage = curPage;
		this.pageSize = pageSize;
		startIndex = (curPage-1)*pageSize;
		endIndex = pageSize;
	}
	
	public void build(){
		startIndex = (curPage-1)*pageSize;
		endIndex = pageSize;
	}
	
	
	public int getStartIndex() {
		return (curPage-1)*pageSize;
	}

	public int getEndIndex() {
		return pageSize;
	}

	public Integer getTotalRecords() {
		return totalRecords == null ? 0 : totalRecords;
	}

	public void setTotalRecords(Integer totalRecords) {
		this.totalRecords = totalRecords;
	}

	public int getCurPage() {
		return curPage;
	}
	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}
	
	public Integer getTotalPages()
	{
		try {
			Integer totalPages = Double.valueOf(
					Math.ceil(getTotalRecords() / (double) getPageSize()))
					.intValue();
			return totalPages;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	
}
